package com.myhouse.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.myhouse.entity.User;

public class SecurityInterceptor extends HandlerInterceptorAdapter{

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		User user = (User) request.getSession().getAttribute("user");
		if(user==null || !user.getName().equals("管理员")) {
			String path = request.getContextPath()+"/login";
			response.sendRedirect(path);
			return false;
		}
		return true;
	}
}
